package com.zx._01_基础._012_反射;

import com.zx._01_基础._012_反射.案例.UserDao;
import com.zx._01_基础._012_反射.案例.UserDaoImpl;
import com.zx.common.entity.User;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;

public class 获得泛型类型 {

    private List<User> users1 = new ArrayList<>() {{
        add(new User(1L, "tom", 18));
    }};

    private List<User> users2 = new ArrayList<>();

    private UserDao userDao = new UserDaoImpl();

    @Before
    public void before() {
        System.out.println("###################");
    }

    @Test
    public void test01() {
        System.out.println("应该是com.zx.common.entity.User=" + userDao.getEntityClass().getName());
    }

    @Test
    public void test02() {
        // 如果有数据的话，直接获得元素即可
        Class<?> aClass = test02(users1);
        System.out.println(aClass);
    }

    public <T> Class<T> test02(List<T> list) {
        Object o = list.get(0);
        return (Class<T>) o.getClass();
    }


    @Test
    public void test03() {

    }
}
